﻿
function countryChange(country_value,lang)
{	

if ( country_value != "VN" )
	{
		newDivStr="<input type=text name='city' id='city' style='width:250px;' class='textfiled'>";
		getobj('ext_city').innerHTML=newDivStr;
	}
	else
	{
		var mydata =  "do=list_city&country="+country_value+'&lang='+lang;
		var url = ROOT + "modules/member/ajax/ajax_member.php" ;
		ajax = new sack( url );
		ajax.method = "GET" ;
		ajax.element = "ext_city";
		ajax.runAJAX(mydata);
	}
}

/*--------------- LoadAjaxMember ----------------*/
function LoadAjaxMember(doAction,str_value,ext_display) {
	var mydata =  "do="+doAction + str_value;
	var url = ROOT+'modules/member/ajax/ajax_member.php';
	ajax = new sack(url);
	ajax.method = "GET" ;
	ajax.element = ext_display;
	ajax.runAJAX(mydata); 
}

function del_item(theURL) {
   if (confirm(mess_error['are_you_sure_del'])) {
			window.location.href=theURL;
	 }
	 else {
			alert ('Phew~');
	 } 
}

function selected_item(){
		var name_count = document.manage.length;
		for (i=0;i<name_count;i++){
			if (document.manage.elements[i].checked){
				return true;
			}
		}
		alert(mess_error['please_chose_item']);
		return false;
	}
	
function del_selected(action) {
		if (selected_item()){
			question = confirm(mess_error['are_you_sure_cancel'])
			if (question != "0"){
				document.manage.action=action;
				document.manage.submit();
			}else{
			  alert ('Phew~');
		    }
		}
	
}


function do_submit(action) {
	document.manage.do_action.value=action;
	if (action=="del"){
		if (selected_item()){
			question = confirm(mess_error['are_you_sure_cancel'])
			if (question != "0"){
				document.manage.submit();
			}else{
			  alert ('Phew~');
		    }
		}
	}else{
		document.manage.submit();
	}
	
}
	
function checkall()	{
	for ( i=0;i < document.manage.elements.length ; i++ ){
		if (i>0 && document.manage.elements[i].type=="checkbox"){
			row_id = 'row_'+document.manage.elements[i].value;
		}else{
			row_id="";
		}
		
		if ( document.manage.all.checked==true ){
			document.manage.elements[i].checked = true;
			if (row_id!="" ){
				getobj(row_id).className = "row_select";
			}
		}
		else{
			document.manage.elements[i].checked  = false;
			if (row_id!="" ){
				if (i%2==0)
					getobj(row_id).className = "row1";
				else
					getobj(row_id).className = "row2";
			}
		}
		
	}
}

function select_row(row_id)	{

	cur_class = getobj(row_id).className;
	if (cur_class=="row_select"){
		getobj(row_id).className ="row1";	
	}else{
		getobj(row_id).className = "row_select";
	}

}
$(document).ready(function () {
	do_Test_MaKH = function () 
	{ 
		var ma_kh = $("#ma_kh").val();
		var mem_id = $("#mem_id").val();
 	  var mydata =  "do=do_test_makh&ma_kh="+ma_kh+"&mem_id="+mem_id;  
		$.ajax({
			async: true,
			dataType: 'json',
			url: ROOT+"load_ajax.php?do=do_test_makh&ma_kh="+ma_kh+"&mem_id="+mem_id,
			type: 'GET',
			data: mydata ,
			success: function (data) {
				
				if(data.ok != 0)	{
					$("#ma_kh").val(data.ma_kh)	;
				}	else {
					$("#ma_kh").val('') ; 		
					jAlert("Mã khách hàng này đã tồn tại","Báo lỗi",function(){$("#ma_kh").focus(); } );
				}	   
			}
		})
	};
	
	$('#btnEdit').click(function(){
		$.ajax({
			url: 'thanhvien.aspx?act=update',
			type: "POST",
			data: $('#frmMember').serialize(),
			dataType: 'json',
			success: function(data){
				alert('Cập nhật thành công');	
			}
		});
		return false;
	});
	
});
